﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Text.RegularExpressions;
using Estimate.Common.DBFieldTypes;
using Estimate.Common.Entity;

namespace Estimate.Common.Estimate
{
    /// <summary>
    /// 计算气温
    /// </summary>
    public class TempScoreCalculate
    {

        public  readonly int EmptyForecast = -100;
        public  readonly int LackForecast = -101;
        public  readonly int LackReal = -102;
        public  readonly int ForecastError = -103;
        public  readonly int RealError = -104;
        public  readonly int EmptyReal = -105;

        public void TempDetail(TempScore tempScore,float _offset)
        {
            if (_offset == EmptyForecast)
                tempScore.EmptyForecast++;
            else if (_offset == ForecastError)
                tempScore.ForecastError++;
            else if (_offset == LackForecast)
                tempScore.LackForecast++;
            else if (_offset == LackReal)
                tempScore.LackReal++;
            else if (_offset == RealError)
                tempScore.RealError++;
            else if (_offset == EmptyReal)
                tempScore.EmptyReal++;
            else
                tempScore.OffsetList.Add(_offset);
           
        }

        /// <summary>
        /// FullInfoReport类计算气温的方法
        /// </summary>
        /// <param name="tempScore">存储气温分数的对象</param>
        /// <param name="semi"></param>
        public void CulculateTemperatureScoreBySemiString(Dictionary<string, Dictionary<ForeSpanType, TempScore>> TempScores, ForeEntity Semi, ForeSpanType Span, Dictionary<string, string> CityCodes, Dictionary<DateTime, Dictionary<ForeClockType, Dictionary<ForeSendpointType, List<ScheduleEntity>>>> Schedules)
        {
            if (Semi.Semi == "") return;

            foreach (string s in Semi.Semi.Split(new char[] { '|' }))
            {
                if (s == "")   continue;

                string[] oserial = s.Split(new char[] { ';' });
 
                if (oserial[0] == "58265" || oserial[0] == "58358")
                    continue;

                if (oserial[0] == "58252")
                    oserial[0] = "58248";

                string FStNum = oserial[0]; // 预报站号

                List<string> keys = new List<string>();

                if (CityCodes != null)
                {
                    if (!GlobalFunction.CitiesContains( keys, FStNum, CityCodes))
                        continue;
                }
                else if (Schedules != null)
                {
                    if (!GlobalFunction.SchedulesContains(keys, FStNum, Semi, Schedules))
                        continue;
                }

                float _offset = -1000;
                if (oserial.Length < 2)
                    _offset = 0;
                else
                    float.TryParse(oserial[1].ToString(), out _offset);
                if (keys.Count == 0)
                    TempDetail(TempScores[""][Span], _offset);
                else
                {
                    foreach (string key in keys)
                    {
                            TempDetail(TempScores[key][Span], _offset);
                    }
                }
            }

        }

      
    }
}
